class Solution(object):
    def smallestNumber(self, num):
        if num == 0:
            return 0
        if num > 0:
            nums = list(str(num))
            nums.sort()
            index = 0
            while index < len(nums):
                if nums[index] != '0':
                    break
                else:
                    index += 1
            new_nums = nums[index] + '0' * index + ''.join(nums[index + 1:])
            return int(new_nums)
        else:
            num = - num
            nums = list(str(num))
            nums.sort(reverse=True)
            return - int(''.join(nums))
